<?php
namespace Home\Controller;
use Think\Controller;
class MoreController extends Controller {

    //测试功能
    // 获取所有的product name 信息
    public function get_all_product_name()
    {
        $DB = M("product");
        $res = $DB->field("name")->select();

        $fp = fopen("products.json", "w");
        fwrite($fp, json_encode($res));
        fclose($fp);

        // echo json_encode($res);

    }

    // 本地读取所有产品名字
    public function show_all_product_name()
    {
        $data = json_decode(file_get_contents("products.json"));
        print_r($data);
    }

    //匹配是否又一致的第三方数据
    public function find_match_from_thirdparty()
    {
        $data = json_decode(file_get_contents("products.json"),ture);
        foreach ($data as $key => $value) {
            # code...
            $tmp = $this->chk_if_match_with_product_in_thirdparty($value['name']);
            if($tmp)
            {
                echo $value['name']."<br/>";
            }
        }
    }

    // 判断是否有匹配
    public function chk_if_match_with_product_in_thirdparty($name)
    {
        $DB = M("third_party_product");
        $map['product_name'] = $name;

        $res = $DB->where($map)->find();

        if(!empty($res))
        {
            return $res;
        }
        else
        {
            return FALSE;
        }
    }


}
?>
